﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

typedef struct ListNode
{
	int val;
	struct ListNode* next;
}LN;

LN* node(int x)
{
	LN* newnode = (LN*)malloc(sizeof(LN));
	if (newnode == NULL)
	{
		perror("malloc:");
		exit(1);
	}
	newnode->val = x;
	newnode->next = NULL;
	return newnode;
}
void buynode(LN** pphaed)
{
	LN* haed = (LN*)malloc(sizeof(LN));
	LN* pucr = haed;
	for (int i = 1; i <= 6; i++)
	{
		pucr->next = node(i);
		pucr = pucr->next;
	}
	*pphaed = haed->next;
	free(haed);
	haed = NULL;
}
LN* middlenode(LN* phead)
{
	LN* slow, * fast;
	slow = fast = phead;
	// 2slow=fast;
	while (fast && fast->next)
	{
		slow = slow->next;
		fast = fast->next->next;
	}
	return slow;
}
void printnode(LN* p)
{
	LN* pucr = p;
	while (pucr)
	{
		printf("%d ", pucr->val);
		pucr = pucr->next;
	}
	printf("\n");
}
int main()
{
	//创建节点
	LN* p = NULL;
	buynode(&p);
	printnode(p);
	LN* ret = middlenode(p);
	printnode(ret);
	return 0;
}
